import { formateDateTimeNew, formatString2Number, formatUnit } from './format';
import { ConfigItem } from '@/types/tester';
import { unitMap } from '@/config';

// 测量方式
const method = {
  '0x01': '正接',
  '0x02': '反接',
  '0x03': 'CVT自激法',
  '0x04': '低压反接屏蔽法',
};

const winding = {
  '0x01': '高压绕组',
  '0x02': '中压绕组',
  '0x03': '低压绕组',
};

export const dielectricConfig: ConfigItem[] = [
  {
    label: '测试时间',
    key: 'datetime',
    start: 0,
    length: 7,
    dataType: 'unit8',
    format: formateDateTimeNew,
    serverKey: 'monitorTime',
  },
  {
    label: '相别',
    key: 'phase',
    start: 0,
    length: 0,
    dataType: 'char',
    serverKey: 'phase',
    editable: true,
    editType: 'select',
    editOptions: ['A相', 'B相', 'C相'],
  },
  {
    label: '设备类型',
    key: 'deviceType',
    start: 0,
    length: 0,
    dataType: 'char',
    precision: 0,
    serverKey: 'deviceType',
    editable: true,
    editType: 'select',
    editOptions: ['油纸电容型', '充油型', '胶纸电容型', '充胶式', '油纸', '膜纸复合', '电容型-油纸', '电容型-胶纸', '电容型-气体', '电容型-干式', '非电容型-充油', '非电容型-充胶', '非电容型-胶纸', '本体', '支架'],
  },
  {
    label: '环境温度',
    key: 'ambientTemperature',
    start: 0,
    length: 0,
    dataType: 'char',
    serverKey: 'ambientTemperature',
    editable: true,
    editType: 'input',
    unit: unitMap['0x11'],
  },
  {
    label: '空气湿度',
    key: 'airHumidity',
    start: 0,
    length: 0,
    dataType: 'char',
    serverKey: 'airHumidity',
    editable: true,
    editType: 'input',
    unit: unitMap['0x08'],
  },
  {
    label: '温度',
    key: 'temperature',
    start: 0,
    length: 0,
    dataType: 'float',
    precision: 0,
    serverKey: 'temperature',
    editable: true,
    editType: 'input',
    unit: unitMap['0x11'],
    serverFormat: (value) => formatString2Number(value as string)
  },
  {
    label: '备注',
    key: 'remark',
    start: 0,
    length: 0,
    dataType: 'char',
    serverKey: 'remark',
    editable: true,
    editType: 'input',
  },
  {
    label: '测量方法',
    key: 'method',
    start: 7,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, method),
    serverKey: 'measurementMothod',
  },
  {
    label: '介质损耗',
    key: 'dielectric',
    start: 8,
    length: 4,
    dataType: 'float',
    unit: unitMap['0x08'],
    precision: 3,
    serverKey: 'dielectricLoss',
  },
  {
    label: '电容量',
    key: 'capacitance',
    start: 12,
    length: 4,
    dataType: 'float',
    readUnit: 'capacitanceUnit',
    description: '自激法时为 C1 电容量，非自激法时为电容量',
    precision: 2,
    serverKey: 'capacitance',
    serverUnit: unitMap['0x27'],
  },
  {
    label: 'C2介质损耗',
    key: 'c2DielectricLoss',
    start: 16,
    length: 4,
    dataType: 'float',
    unit: unitMap['0x08'],
    precision: 3,
    description: 'C2介质损耗，非自激法时无效，置为 0xFFFFFFFF，单位使用%',
    serverKey: 'dielectricLossTwo',
  },
  {
    label: 'C2电容量',
    key: 'c2Capacitance',
    start: 20,
    length: 4,
    dataType: 'float',
    readUnit: 'capacitanceUnit',
    precision: 2,
    description: 'C2 电容量，非自激法时无效，置为 0xFFFFFFFF',
    serverKey: 'capacitanceTwo',
    serverUnit: unitMap['0x27'],
  },
  {
    label: '电容量单位',
    key: 'capacitanceUnit',
    start: 24,
    length: 1,
    dataType: 'unit8',
    description: '电容量单位，参见状态量单位编码',
    format: formatUnit,
    hide: true,
  },
  {
    label: '试验电压',
    key: 'voltage',
    start: 25,
    length: 4,
    dataType: 'float',
    readUnit: 'voltageUnit',
    description: '试验电压数值',
    serverKey: 'voltage',
    serverUnit: unitMap['0x05'],
    precision: 2,
  },
  {
    label: '电压单位',
    key: 'voltageUnit',
    start: 29,
    length: 1,
    dataType: 'unit8',
    description: '电压单位，参见状态量单位编码',
    format: formatUnit,
    hide: true,
  },
  {
    label: '试验电流',
    key: 'testCurrent',
    start: 30,
    length: 4,
    dataType: 'float',
    description: '试验电流数值',
    precision: 2,
    readUnit: 'currentUnit',
    serverKey: 'electricCurrent',
    serverUnit: unitMap['0x09'],
  },
  {
    label: '电流单位',
    key: 'currentUnit',
    start: 34,
    length: 1,
    dataType: 'unit8',
    description: '电流单位，参见状态量单位编码',
    format: formatUnit,
    hide: true,
  },
  {
    label: '测试绕组',
    key: 'testWinding',
    start: 35,
    length: 1,
    dataType: 'unit8',
    description: '自激法测试绕组介损时有效',
    serverKey: 'testWinding',
    format: value => formatUnit(value, winding),
  },
];
